<template>
  <div id="app">
    <keep-alive>
      <router-view/>
    </keep-alive>

    <div class="play" >
      <ul>
        <router-link :to="{ name: 'nav'}"><li>首页</li></router-link>
        <li @click='next'>下一页</li>
        <li @click='autoplay' :class='{onplay : onplay}'>自动播放</li>
        <li @click='pause'>暂停</li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data(){
    return {
      router : this.$router.options.routes,
      pageTimer : null,
      onplay : false,
    }
  },
  methods : {
    next(){
      let _length = this.router.length - 1;
      if(this.currentPage == _length){
        this.$router.push('/home');
      }else {
        this.$router.push(this.router[this.currentPage + 1].path);
      }
    },
    autoplay(){
      this.pause()
      this.onplay = true;
      if(this.$route.name == 'nav'){
        this.next();
      }
      this.pageTimer = setInterval(()=>{
        this.next();
      },60000)
    },
    pause(){
      clearInterval(this.pageTimer);
      this.onplay = false;
    }
  },
  computed : {
    currentPage(){
      let _index ;
      this.router.forEach((elem,index) => {
        if(elem.path == this.$route.path){
          _index = index;
        }
      })
      return _index
    }
  }
}
</script>

<style lang='scss'>
@import './assets/sass/reset.scss';
body {
  width: 100%;
  height: 100%;
  background-color : #152985;
}
.play {
  position : absolute;
  width: 40 / 1920 * 100%;
  left: 0;
  top: 0;
  bottom : 0;
  vertical-align: middle;
  transition: 1s all;
  ul {
    position: absolute;
    left: -200px;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    height: 200px;
    box-sizing: border-box;
    border : 1px solid #00fffc;
    border-left: none;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    opacity: 0;
    transition: .8s;
    a{
      text-decoration: none;
    }
    li{
      width: 130px;
      height: 30px;
      background-color: #49d9fe;
      margin-left: 14px;
      text-align: center;
      line-height: 30px;
      color: #015a70;
      cursor: pointer;
      &::before {
        display: block;
        position: absolute;
        content : '';
        width: 10px;
        height: 30px;
        background-color: #b3d465;
        margin-left: -14px;
      }
      &:hover {
        background-color: #b3d465;
      }
    }
    li.onplay {
      background-color: rgb(159, 255, 1)
    }
  }
  &:hover {
    ul{
      opacity: 1;
      left: 0;
    }
  }
}
</style>
